// Agent r3 in project skygarden

/* Initial beliefs and rules */
at_vegetable(X,Y) :- pos(AgX,AgY) & AgX==X & AgY==Y.

+infoAboutVeg(Alive,Gray) : Alive == 0 & Gray \== 0 & not start_cleaning
	<-	.print("Now I'm going to cleaning garden !!");
		+start_cleaning;
		!goto_cleaning_garden.

/* Initial goals */


/* Plans */

+!goto_cleaning_garden : pos(AgX,AgY) & math.closest_vegetable(AgX,AgY,3,X,Y) & not at_vegetable(X,Y)
	<-	math.get_direction(1,AgX,AgY,X,Y,D);
		do(D);
		!goto_cleaning_garden.
	
+!goto_cleaning_garden : pos(AgX,AgY) & math.closest_vegetable(AgX,AgY,3,X,Y) & at_vegetable(X,Y)
	<-	?setOfVeg(S);
		.send(S,achieve,who_die(AgX,AgY));
		cleaning_garden(AgX,AgY);
		math.get_direction(1,AgX,AgY,X,Y,D);
		do(D);
		!goto_cleaning_garden.
		
+!goto_cleaning_garden : true
	<-	.print("All gray vegetable is cleaned. I'm going to home.");
		!goto_home.
		
+!goto_home : pos(AgX,AgY) & not at_vegetable(17,9)
	<-	math.get_direction(1,AgX,AgY,17,9,D);
		do(D);
		!goto_home.
		
+!goto_home : true
	<-	.print("I'm at home and waiting for cleaning garden!");
		-start_cleaning.
	
